{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0073d9ac-e4ed-4298-afdf-23aa3bff7c9e",
   "metadata": {},
   "source": [
    "# for 循环"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bf51c2ac-f840-4396-ac27-544198de3524",
   "metadata": {},
   "source": [
    "```python\n",
    "for <variable> in <sequence>:\n",
    "    <statements>\n",
    "else:\n",
    "    <statements>\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ebe24f51-abdd-43db-85cd-1cdd212289f1",
   "metadata": {},
   "source": [
    ">for item in iterable:\n",
    ">      \\# 循环主体\n",
    "> else:\n",
    ">       \\# 循环结束后执行的代码"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d7397daf-0e40-41ea-a23c-c0cc4500032b",
   "metadata": {
    "tags": []
   },
   "source": [
    "![img](https://www.runoob.com/wp-content/uploads/2013/11/A71EC47E-BC53-4923-8F88-B027937EE2FF.jpg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "f4f43957-2c07-4452-95dd-0194fb709286",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "sites = [\"Baidu\", \"Google\",\"JD\",\"Taobao\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "feedb8ab-56a3-4341-a36f-304a1b82385a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Baidu\n",
      "Google\n",
      "Runoob\n",
      "Taobao\n"
     ]
    }
   ],
   "source": [
    "for site in sites:\n",
    "    print(site)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "52bd7e86-675a-46ed-8b37-7c6a3d3e740c",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "B\n",
      "a\n",
      "i\n",
      "d\n",
      "u\n"
     ]
    }
   ],
   "source": [
    "for i in sites[0]:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "b649c150-f0d2-41e9-8241-e0c27b4f98cf",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n"
     ]
    }
   ],
   "source": [
    "for number in range(1, 6):\n",
    "    print(number)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "43fec741-b36c-45f8-9631-330b5d5f263a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "Finally finished!\n"
     ]
    }
   ],
   "source": [
    "for x in range(6):\n",
    "    print(x)\n",
    "else:\n",
    "    print(\"Finally finished!\")   # 执行完for 后执行   重点：执行完"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
